
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { StudentService } from './student.service';
import { CreateStudentDto, BaseStudentDto, UpdateStudentDto, QueryStudentDto, ListStudentDto } from './dto/student.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';

@ApiTags('学生管理')
@Controller('edutation/student')
export class StudentController {
constructor(private readonly studentService: StudentService) {}
    @ApiOperation({ summary: '学生管理-创建',  })
    @ApiDataResponse(BaseStudentDto)
    @RequirePermission('edutation:student:add')
    @Post()
    @RepeatSubmit()
    create(@Body() body: CreateStudentDto,@UserTool() { injectCreate }: UserToolType) {
        return this.studentService.create(injectCreate(body));
    }


    @ApiOperation({ summary: '学生管理-列表',  })
    @ApiDataResponse(ListStudentDto, true, true)
    @RequirePermission('edutation:student:list')
    @Get('list')
    findAll(@Query() query: QueryStudentDto) {
        return this.studentService.findAll(query);
    }


    @ApiOperation({  summary: '学生管理-详情',    })
    @ApiDataResponse(BaseStudentDto)
    @RequirePermission('edutation:student:query')
    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.studentService.findOne(+id);
    }


    @ApiOperation({ summary: '学生管理-修改',  })
    @ApiDataResponse()
    @RequirePermission('edutation:student:edit')
    @Put()
    @RepeatSubmit()
    update(@Body() body: UpdateStudentDto,@UserTool() { injectUpdate }: UserToolType) {
        return this.studentService.update(injectUpdate(body));
    }


    @ApiOperation({  summary: '学生管理-删除', })
    @ApiDataResponse()
    @RequirePermission('edutation:student:remove')
    @Delete(':ids')
    remove(@Param('ids') ids: string) {
        const studentIdList = ids.split(',').map((id) => +id);
        return this.studentService.remove(studentIdList);
    }
}